home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / man / lib.fmt / c / malloc.man < prev    next >
Encoding:
Text File  |  1990-10-06  |  3.9 KB  |  133 lines

  1.  
  2.  
  3.  
  4. MALLOC                C Library Procedures                 MALLOC
  5.  
  6.  
  7.  
  8. NNAAMMEE
  9.      malloc, free, realloc, calloc, alloca - memory allocator
  10.  
  11. SSYYNNOOPPSSIISS
  12.      #include <stdlib.h>
  13.  
  14.      cchhaarr **mmaalllloocc((ssiizzee))
  15.      uunnssiiggnneedd ssiizzee;;
  16.  
  17.      ffrreeee((ppttrr))
  18.      cchhaarr **ppttrr;;
  19.  
  20.      cchhaarr **rreeaalllloocc((ppttrr,, ssiizzee))
  21.      cchhaarr **ppttrr;;
  22.      uunnssiiggnneedd ssiizzee;;
  23.  
  24.      cchhaarr **ccaalllloocc((nneelleemm,, eellssiizzee))
  25.      uunnssiiggnneedd nneelleemm,, eellssiizzee;;
  26.  
  27.      cchhaarr **aallllooccaa((ssiizzee))
  28.      iinntt ssiizzee;;
  29.  
  30. DDEESSCCRRIIPPTTIIOONN
  31.      _M_a_l_l_o_c and _f_r_e_e provide a general-purpose memory allocation
  32.      package.  _M_a_l_l_o_c returns a pointer to a block of at least
  33.      _s_i_z_e bytes beginning on a word boundary.
  34.  
  35.      The argument to _f_r_e_e is a pointer to a block previously
  36.      allocated by _m_a_l_l_o_c; this space is made available for
  37.      further allocation, but its contents are left undisturbed.
  38.  
  39.      Needless to say, grave disorder will result if the space
  40.      assigned by _m_a_l_l_o_c is overrun or if some random number is
  41.      handed to _f_r_e_e.
  42.  
  43.      _M_a_l_l_o_c maintains multiple lists of free blocks according to
  44.      size, allocating space from the appropriate list.  It calls
  45.      _s_b_r_k (see _b_r_k(2)) to get more memory from the system when
  46.      there is no suitable space already free.
  47.  
  48.      _R_e_a_l_l_o_c changes the size of the block pointed to by _p_t_r to
  49.      _s_i_z_e bytes and returns a pointer to the (possibly moved)
  50.      block.  The contents will be unchanged up to the lesser of
  51.      the new and old sizes.  The Sprite version of _r_e_a_l_l_o_c
  52.      differs from other UNIX versions in that _p_t_r may not point
  53.      to a free block (in other UNIX versions _p_t_r _m_a_y _p_o_i_n _t_o _a
  54.      _b_l_o_c_k _f_r_e_e_d _s_i_n_c_e _t_h_e _l_a_s_t _c_a_l_l _t_o _m_a_l_l_o_c, _c_a_l_l_o_c, or _r_e_a_l_-
  55.      _l_o_c).
  56.  
  57.      _C_a_l_l_o_c allocates space for an array of _n_e_l_e_m elements of
  58.      size _e_l_s_i_z_e. The space is initialized to zeros.
  59.  
  60.  
  61.  
  62.  
  63. Sprite v1.0               May 14, 1986                          1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. MALLOC                C Library Procedures                 MALLOC
  71.  
  72.  
  73.  
  74.      _A_l_l_o_c_a allocates _s_i_z_e bytes of space in the stack frame of
  75.      the caller.  This temporary space is automatically freed on
  76.      return.
  77.  
  78.      Each of the allocation routines returns a pointer to space
  79.      suitably aligned (after possible pointer coercion) for
  80.      storage of any type of object.
  81.  
  82. SSEEEE AALLSSOO
  83.      brk(2), pagesize(2)
  84.  
  85. DDIIAAGGNNOOSSTTIICCSS
  86.      _M_a_l_l_o_c, _r_e_a_l_l_o_c and _c_a_l_l_o_c return a null pointer (0) if
  87.      there is no available memory or if the arena has been
  88.      detectably corrupted by storing outside the bounds of a
  89.      block.  _M_a_l_l_o_c may be recompiled to check the arena very
  90.      stringently on every transaction; those sites with a source
  91.      code license may check the source code to see how this can
  92.      be done.
  93.  
  94. BBUUGGSS
  95.      When _r_e_a_l_l_o_c returns 0, the block pointed to by _p_t_r may be
  96.      destroyed.
  97.  
  98.      The current implementation of _m_a_l_l_o_c does not always fail
  99.      gracefully when system memory limits are approached.  It may
  100.      fail to allocate memory when larger free blocks could be
  101.      broken up, or when limits are exceeded because the size is
  102.      rounded up.  It is optimized for sizes that are powers of
  103.      two.
  104.  
  105.      _A_l_l_o_c_a is machine dependent; its use is discouraged.
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129. Sprite v1.0               May 14, 1986                          2
  130.  
  131.  
  132.  
  133.